home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1993, 1994 Marc Parmet.
- * This file is part of the Macintosh port of GNU Emacs.
- *
- * GNU Emacs is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
- /* Throughout this file we save and restore ports around calls to set them. This
- is because we allow use of SetPort from lisp, and we must make sure this
- notion of current port doesn't change. A bad case would be code like:
-
- (SetPort gp)
- ... ;;; other lisp code
- (LineTo x y)
-
- where the code between the SetPort and the LineTo invokes garbage collection,
- resulting in the familiar message "Garbage collection...done", the display of
- which requires changes in the current port. We better restore it.
- */
-
- #if defined(THINK_C)
- #include <MacHeaders>
- #else
- #include <Types.h>
- #include <Memory.h>
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <Fonts.h>
- #include <ToolUtils.h>
- #endif
-
- #include <Palettes.h>
- #include <GestaltEqu.h>
- #include "stdio.h"
- #include "signal.h"
- #include "config.h"
- #include "lisp.h"
- #include "termhooks.h"
- #include "termchar.h"
-
- enum {
- plt_white,
- plt_black,
- plt_grey,
- plt_back,
- plt_frame,
- plt_text,
- plt_status,
- plt_status_text,
- plt_cursor,
- plt_cursor_text,
- plt_size
- };
-
- static struct {
- WindowRecord wr0;
- WindowPtr wp;
- WCTabHandle ctab5_color,ctab5_bw;
- FontInfo fi;
- short lineHeight;
- #define CONSOLE(X,Y) console.backup[console.cols * (Y) + (X)]
- char *backup,*reverse;
- short cx,cy,rows,cols;
- } console;
- #define LEFT_MARGIN 4
- #define TOP_MARGIN 2
- static int flexlines;
- static char in_emacs_update;
- static Rect huge = { -32767,-32767,32767,32767 };
- static char have_CQD;
- static char window_depth_cache_valid;
- static char window_depth_cache;
-
- static min (a,b) { return a<b ? a : b; }
-
- static int
- use_color(void)
- {
- GDHandle gd;
- PaletteHandle ph;
- Point origin;
- GrafPtr gp;
- Rect device_rect,console_rect,common;
-
- if (!have_CQD) return 0;
-
- ph = GetPalette(console.wp);
- if ((**ph).pmEntries != plt_size) return 0;
-
- if (!window_depth_cache_valid) {
- console_rect = console.wp->portRect;
- origin.h = origin.v = 0;
- GetPort(&gp);
- SetPort(console.wp);
- LocalToGlobal(&origin);
- SetPort(gp);
- OffsetRect(&console_rect,origin.h,origin.v);
- window_depth_cache = 4;
- for (gd = GetDeviceList(); gd != 0L; gd = GetNextDevice(gd)) {
- device_rect = (**(**gd).gdPMap).bounds;
- if (SectRect(&device_rect,&console_rect,&common))
- window_depth_cache = min((**(**gd).gdPMap).pixelSize,window_depth_cache);
- }
- window_depth_cache_valid = 1;
- }
-
- return window_depth_cache >= 4;
- }
-
- static void
- compute_position(int x,int y,int *sx,int *sy)
- {
- *sx = LEFT_MARGIN + x * console.fi.widMax;
- *sy = TOP_MARGIN + y * console.lineHeight;
- }
-
- static void
- extract_position(int sx,int sy,int *x,int *y)
- {
- *x = (sx - LEFT_MARGIN) / console.fi.widMax;
- *y = (sy - TOP_MARGIN) / console.lineHeight;
- }
-
- static void
- set_position(int x,int y)
- {
- int sx,sy;
- compute_position(x,y,&sx,&sy);
- MoveTo(sx,sy + console.fi.ascent);
- }
-
- static char cursor_state;
- enum { cursor_state_not_shown, cursor_state_solid, cursor_state_outline };
-
- static void
- draw_cursor1(int state,int visible)
- {
- Rect r;
- int sx,sy;
-
- if (state == cursor_state_not_shown) return;
-
- compute_position(console.cx,console.cy,&sx,&sy);
- SetRect(&r,sx,sy,sx + console.fi.widMax,sy + console.fi.ascent + console.fi.descent);
- if (use_color()) {
- if (visible) {
- PmForeColor(plt_cursor);
- if (state == cursor_state_outline)
- FrameRect(&r);
- else
- PaintRect(&r);
- }
- else
- EraseRect(&r);
- PmForeColor(!visible || state == cursor_state_outline ? plt_text : plt_cursor_text);
- MoveTo(sx,sy + console.fi.ascent);
- DrawChar(CONSOLE(console.cx,console.cy));
- }
- else {
- PenMode(patXor);
- if (state == cursor_state_outline)
- FrameRect(&r);
- else
- PaintRect(&r);
- PenNormal();
- }
- }
-
- static void
- erase_cursor(void)
- {
- draw_cursor1(cursor_state,0);
- cursor_state = cursor_state_not_shown;
- }
-
- static void
- draw_cursor(void)
- {
- int newstate = ((WindowPeek)console.wp)->hilited ? cursor_state_solid :
- cursor_state_outline;
- if (newstate == cursor_state) return;
- draw_cursor1(cursor_state,0);
- cursor_state = newstate;
- draw_cursor1(cursor_state,1);
- }
-
- static void
- erase_text(int x1,int y1,int x2,int y2,int highlighted)
- {
- int sx1,sx2,sy1,sy2;
- Rect r;
-
- compute_position(x1,y1,&sx1,&sy1);
- compute_position(x2,y2,&sx2,&sy2);
- SetRect(&r,sx1,sy1,sx2 + console.fi.widMax,sy2 + console.fi.ascent + console.fi.descent);
- if (highlighted) {
- if (use_color()) PmForeColor(plt_status);
- PaintRect(&r);
- }
- else
- EraseRect(&r);
- }
-
- static void
- my_move_cursor_hook(int y,int x)
- {
- GrafPtr gp;
-
- if (!in_emacs_update) GetPort(&gp), SetPort(console.wp), erase_cursor();
- console.cx = x;
- console.cy = y;
- if (!in_emacs_update) draw_cursor(), SetPort(gp);
- }
-
- static void
- set_text_mode_and_color(int row)
- {
- if (use_color())
- if (console.reverse && console.reverse[row])
- PmForeColor(plt_status_text);
- else
- PmForeColor(plt_text);
- }
-
- static void
- my_output_chars_hook(char *s,int n)
- {
- GrafPtr gp;
- int chars_to_write = min(n,console.cols - console.cx);
-
- GetPort(&gp);
- SetPort(console.wp);
- if (!in_emacs_update) erase_cursor();
- erase_text(console.cx,console.cy,
- console.cx+chars_to_write-1,console.cy,
- console.reverse && console.reverse[console.cy]);
- set_position(console.cx,console.cy);
- set_text_mode_and_color(console.cy);
- DrawText(s,0,chars_to_write);
- if (console.backup) memcpy(&CONSOLE(console.cx,console.cy),s,chars_to_write);
- console.cx += chars_to_write;
- if (!in_emacs_update) draw_cursor();
- SetPort(gp);
- }
-
- static void
- my_clear_screen_hook(void)
- {
- GrafPtr gp;
-
- GetPort(&gp);
- SetPort(console.wp);
- erase_text(0,0,console.cols-1,console.rows,0);
- cursor_state = cursor_state_not_shown;
-
- if (console.backup && console.reverse) {
- memset(console.backup,' ',console.cols * console.rows);
- memset(console.reverse,0,console.rows);
- }
- console.cx = console.cy = 0;
- if (!in_emacs_update) draw_cursor();
- SetPort(gp);
- }
-
- static void
- my_clear_end_of_line_hook(int first_unused_hpos)
- {
- GrafPtr gp;
- int last_col = min(first_unused_hpos,console.cols) - 1;
-
- GetPort(&gp);
- SetPort(console.wp);
- if (!in_emacs_update) erase_cursor();
- erase_text(console.cx,console.cy,last_col,console.cy,
- console.reverse && console.reverse[console.cy]);
- if (!in_emacs_update) draw_cursor();
- if (console.backup) memset(&CONSOLE(console.cx,console.cy),' ',last_col - console.cx + 1);
- SetPort(gp);
- }
-
- static void
- my_ring_bell_hook(void)
- {
- SysBeep(3);
- }
-
- static void
- my_set_terminal_window_hook(int n)
- {
- /* From reading the comments of x11term.c, it sounds like lines number up
- to and including flexlines are affected by scrolling operations. From
- reading the code, it looks like lines numbers up to, but not including,
- flexlines are affected. */
-
- flexlines = (n <= 0 || n > console.rows) ? console.rows : n;
- }
-
- static void
- my_ins_del_lines_hook(int vpos,int n)
- {
- // vpos is the top line of the region being scrolled
- // flexlines is one past the bottom of the region being scrolled
- // n in the number of lines to scroll.
-
- Rect r;
- GrafPtr gp;
- RgnHandle rgn;
- int sx1,sy1,sx2,sy2;
-
- GetPort(&gp);
- SetPort(console.wp);
- if (!in_emacs_update) erase_cursor();
- compute_position(0,vpos,&sx1,&sy1);
- compute_position(console.cols-1,flexlines-1,&sx2,&sy2);
- SetRect(&r,sx1,sy1,sx2 + console.fi.widMax,sy2 + console.fi.ascent + console.fi.descent);
- rgn = NewRgn();
- ScrollRect(&r,0,n*console.lineHeight,rgn);
- DisposeRgn(rgn);
- if (!in_emacs_update) draw_cursor();
- SetPort(gp);
-
- if (console.backup) {
- if (n>0) {
- memmove(&CONSOLE(0,vpos+n),&CONSOLE(0,vpos),
- (flexlines - vpos - n) * console.cols);
- memset(&CONSOLE(0,vpos),' ',n * console.cols);
- }
- else {
- n = -n;
- memmove(&CONSOLE(0,vpos),&CONSOLE(0,vpos+n),
- (flexlines - vpos - n) * console.cols);
- memset(&CONSOLE(0,flexlines - n),' ',n * console.cols);
- }
- }
- }
-
- static void
- my_change_line_highlight_hook(int highlighted,int vpos,int first_unused_hpos)
- {
- GrafPtr gp;
- int last_col = min(first_unused_hpos,console.cols) - 1;
-
- GetPort(&gp);
- SetPort(console.wp);
- my_move_cursor_hook(vpos,0);
- erase_text(0,vpos,console.cols-1,vpos,highlighted);
- if (console.reverse) console.reverse[vpos] = highlighted != 0;
- if (console.backup) memset(&CONSOLE(0,vpos),' ',console.cols);
- SetPort(gp);
- }
-
- static void
- my_reassert_line_highlight_hook(int highlight,int vpos)
- {
- if (console.reverse) console.reverse[vpos] = highlight;
- }
-
- static void
- my_update_begin(int x)
- {
- if (!in_emacs_update) {
- GrafPtr gp;
- GetPort(&gp);
- SetPort(console.wp);
- erase_cursor();
- SetPort(gp);
- }
- ++in_emacs_update;
- }
-
- static void
- my_update_end(int x)
- {
- --in_emacs_update;
- if (!in_emacs_update) {
- GrafPtr gp;
- GetPort(&gp);
- SetPort(console.wp);
- draw_cursor();
- SetPort(gp);
- }
- }
-
- static void
- my_calculate_costs_hook(int extra,int *costvec,int *ncostvec)
- {
- CalcLID(0,screen_width/5,0,0,costvec,ncostvec);
- }
-
- static void
- my_fix_screen_hook(void)
- {
- read_events(0);
- }
-
- static void
- reset_size(int rows,int cols)
- {
- console.rows = rows;
- console.cols = cols;
- if (console.backup) DisposPtr(console.backup), console.backup = 0L;
- console.backup = NewPtr(console.cols * console.rows);
- if (console.reverse) DisposPtr(console.reverse), console.reverse = 0L;
- console.reverse = NewPtr(console.rows);
- console.cx = console.cy = 0;
- if (console.backup && console.reverse) {
- memset(console.backup,' ',console.cols * console.rows);
- memset(console.reverse,0,console.rows);
- }
- }
-
- static Rect
- get_previous_windowsize(void)
- {
- /* This gives a 24 by 80 window using Monaco 9, the default font. */
- static Rect default_rect = { 50,4,50 + 24*11 + 2*TOP_MARGIN,
- 4 + 80*6 + 15 + 2*LEFT_MARGIN };
- Rect r,**preferred_rect;
- int err;
- RgnHandle common_rgn,titlebar_rgn;
-
- err = get_preference('DATA',128,(Handle *)&preferred_rect);
- if (err)
- r = default_rect;
- else {
- r = **preferred_rect;
- DisposHandle((Handle)preferred_rect);
-
- /* Make sure the titlebar appears somewhere on the desktop */
-
- common_rgn = NewRgn();
- titlebar_rgn = NewRgn();
- SetRectRgn(titlebar_rgn,r.left,r.top - 18,r.right,r.top);
- SectRgn(titlebar_rgn,GetGrayRgn(),common_rgn);
- if (EmptyRgn(common_rgn)) r = default_rect;
- DisposeRgn(common_rgn);
- DisposeRgn(titlebar_rgn);
- }
-
- return r;
- }
-
- static void
- windowsize2rowscols(long *rows,long *cols)
- {
- *cols = (console.wp->portRect.right - 15 - 2*LEFT_MARGIN) / console.fi.widMax;
- *rows = (console.wp->portRect.bottom - 2*TOP_MARGIN) / console.lineHeight;
- }
-
- static void
- set_console_font(font,size)
- {
- static int last_font,last_size;
-
- if (font == -1)
- font = last_font;
- else
- last_font = font;
- if (size == -1)
- size = last_size;
- else
- last_size = size;
-
- TextFont(font);
- TextSize(size);
- GetFontInfo(&console.fi);
- console.lineHeight = console.fi.ascent + console.fi.descent + console.fi.leading;
- // The returned value from GetFontInfo is not always right.
- console.fi.widMax = CharWidth('m');
- }
-
- static void
- fixup_colors(void)
- {
- RGBColor c;
- PaletteHandle ph;
- static char last_use_color = -1;
-
- if (!have_CQD) {
- TextMode(srcXor);
- return;
- }
-
- if (last_use_color == use_color()) return;
- last_use_color = use_color();
-
- if (use_color()) {
- SetPort(console.wp);
- TextMode(srcOr);
- PmBackColor(plt_back);
- ph = GetPalette(console.wp);
- GetEntryColor(ph,plt_back,&c);
- (**console.ctab5_color).ctTable[0].rgb = c;
- GetEntryColor(ph,plt_frame,&c);
- (**console.ctab5_color).ctTable[1].rgb = c;
- SetWinColor(console.wp,(WCTabHandle)console.ctab5_color);
- }
- else {
- SetPort(console.wp);
- TextMode(srcXor);
- PmForeColor(plt_black);
- PmBackColor(plt_white);
- SetWinColor(console.wp,(WCTabHandle)console.ctab5_bw);
- }
- }
-
- static void
- init_console(void)
- {
- Rect r;
- Handle h;
- RGBColor c;
- PaletteHandle ph;
- char use_color_pref;
- short **use_color_pref_handle;
- long rows,cols,err,response,fontname,fontsize;
-
- err = Gestalt(gestaltQuickdrawVersion,&response);
- have_CQD = (err == 0 && response >= gestalt8BitQD);
-
- console.wp = (WindowPtr)&console.wr0;
-
- if (have_CQD) {
- GetNewCWindow(136,console.wp,(WindowPtr)-1);
- console.ctab5_color = (WCTabHandle)GetCTable(128);
- console.ctab5_bw = (WCTabHandle)GetCTable(129);
- err = get_preference('DATA',133,(Handle *)&use_color_pref_handle);
- use_color_pref = (err != noErr) || **use_color_pref_handle;
- err = get_preference('pltt',132,(Handle *)&ph);
- if (err == noErr) {
- if (!use_color_pref) ResizePalette(ph,2);
- else if ((**ph).pmEntries == plt_size-1) {
- // An old prefs file missing the last entry
- ResizePalette(ph,plt_size);
- GetEntryColor(ph,plt_text,&c);
- SetEntryColor(ph,plt_cursor_text,&c);
- }
- NSetPalette(console.wp,ph,pmAllUpdates);
- }
- else {
- ph = GetPalette(console.wp);
- if (!use_color_pref) ResizePalette(ph,2);
- SetPaletteUpdates(ph,pmAllUpdates);
- }
- }
- else
- GetNewWindow(136,console.wp,(WindowPtr)-1);
-
- SetPort(console.wp);
- err = get_preference('DATA',130,&h);
- fontname = err ? monaco : **(short **)h;
- err = get_preference('DATA',131,&h);
- fontsize = err ? 9 : **(short **)h;
- set_console_font(fontname,fontsize);
-
- r = get_previous_windowsize();
- MoveWindow(console.wp,r.left,r.top,0);
- SizeWindow(console.wp,r.right - r.left,r.bottom - r.top,0);
- ShowWindow(console.wp);
- r = console.wp->portRect;
- r.right -= 15;
- ValidRect(&r);
- windowsize2rowscols(&rows,&cols);
- reset_size(rows,cols);
- }
-
- void
- apple_init_display(void)
- {
- extern int meta_key;
-
- init_console();
-
- update_begin_hook = (int (*)())my_update_begin;
- update_end_hook = (int (*)())my_update_end;
- move_cursor_hook = (int (*)())my_move_cursor_hook;
- raw_move_cursor_hook = (int (*)())my_move_cursor_hook;
- output_chars_hook = (int (*)())my_output_chars_hook;
- clear_screen_hook = (int (*)())my_clear_screen_hook;
- clear_end_of_line_hook = (int (*)())my_clear_end_of_line_hook;
- ring_bell_hook = (int (*)())my_ring_bell_hook;
- change_line_highlight_hook = (int (*)())my_change_line_highlight_hook;
- reassert_line_highlight_hook = (int (*)())my_reassert_line_highlight_hook;
- ins_del_lines_hook = (int (*)())my_ins_del_lines_hook;
- set_terminal_window_hook = (int (*)())my_set_terminal_window_hook;
- calculate_costs_hook = (int (*)())my_calculate_costs_hook;
- fix_screen_hook = (int (*)())my_fix_screen_hook;
-
- baud_rate = 4*9600;
- fast_clear_end_of_line = 1;
- dont_calculate_costs = 1;
- memory_below_screen = 0;
- must_write_spaces = 1; // Not true, but it seems to run faster with this on.
- char_ins_del_ok = 0; // It runs faster without this feature than with it.
- line_ins_del_ok = 1;
- scroll_region_ok = 1;
- screen_width = console.cols;
- screen_height = console.rows;
- meta_key = 0;
- }
-
- static Rect
- window_rect(Lisp_Object window)
- {
- Rect r;
- int x1,y1,x2,y2;
- Lisp_Object edges;
-
- edges = Fwindow_edges(window);
- compute_position(XINT(Fcar(edges)),XINT(Fcar(Fcdr(edges))),&x1,&y1);
- compute_position(XINT(Fcar(Fcdr(Fcdr(edges)))),
- XINT(Fcar(Fcdr(Fcdr(Fcdr(edges)))))-2,&x2,&y2);
- y2 += console.fi.ascent + console.fi.descent;
- SetRect(&r,x1,y1,x2,y2);
- return r;
- }
-
- static Lisp_Object
- get_clipboard_window(void)
- {
- Lisp_Object clipboard_string,clipboard_buffer,clipboard_window;
-
- clipboard_string = build_string("*clipboard*");
- clipboard_buffer = Fget_buffer(clipboard_string);
- if (NULL(clipboard_buffer)) return Qnil;
- clipboard_window = Fget_buffer_window(clipboard_buffer);
- return clipboard_window;
- }
-
- static void
- draw_console(void)
- {
- int i;
- RgnHandle rgn;
- Rect clipboard_rect;
- Lisp_Object clipboard_window;
-
- if (!((WindowRecord *)console.wp)->hilited) {
- clipboard_window = get_clipboard_window();
- if (!NULL(clipboard_window)){
- clipboard_rect = window_rect(clipboard_window);
- InsetRect(&clipboard_rect,0,1);
- PenPat(&qd.ltGray);
- // if (use_color()) PmForeColor(plt_grey);
- PaintRect(&clipboard_rect);
- PenNormal();
-
- rgn = NewRgn();
- RectRgn(rgn,&clipboard_rect);
- DiffRgn(console.wp->clipRgn,rgn,console.wp->clipRgn);
- DisposeRgn(rgn);
- }
- }
-
- if (console.backup && console.reverse) {
- for (i = 0; i<console.rows; ++i) {
- if (console.reverse[i]) erase_text(0,i,console.cols-1,i,1);
- set_text_mode_and_color(i);
- set_position(0,i);
- DrawText(&CONSOLE(0,i),0,console.cols);
- }
- }
-
- ClipRect(&huge);
- }
-
- void
- my_DrawGrowIcon(WindowPtr w)
- {
- Rect r = w->portRect;
- r.left = r.right - 15;
- ClipRect(&r);
- DrawGrowIcon(w);
- ClipRect(&huge);
- }
-
- void
- fixup_clipboard(int update_contents)
- {
- GrafPtr gp;
- Rect clipboard_rect;
- Lisp_Object mcc,clipboard_window;
-
- if (update_contents && !NULL(mcc = Fintern_soft(build_string("make-clipboard-current"),Qnil)))
- pass_up_lisp_command(Fcons(mcc,Qnil));
-
- clipboard_window = get_clipboard_window();
- if (!NULL(clipboard_window)) {
- clipboard_rect = window_rect(clipboard_window);
- GetPort(&gp);
- SetPort(console.wp);
- InvalRect(&clipboard_rect);
- SetPort(gp);
- }
- }
-
- void
- console_activate(int activate)
- {
- GrafPtr gp;
-
- GetPort(&gp);
- SetPort(console.wp);
- my_DrawGrowIcon(console.wp);
- if (!in_emacs_update) draw_cursor();
- SetPort(gp);
- }
-
- void
- console_update(void)
- {
- GrafPtr gp;
-
- window_depth_cache_valid = 0;
- GetPort(&gp);
- fixup_colors();
- SetPort(console.wp);
- BeginUpdate(console.wp);
- EraseRect(&console.wp->portRect);
- draw_console();
- if (!in_emacs_update) {
- switch (cursor_state) {
- case cursor_state_not_shown: break;
- case cursor_state_solid: draw_cursor1(cursor_state_solid,1); break;
- case cursor_state_outline: draw_cursor1(cursor_state_outline,1); break;
- }
- }
- my_DrawGrowIcon(console.wp);
- EndUpdate(console.wp);
- SetPort(gp);
- }
-
- // These next two are never actually called, but the preprocessor #if's weren't
- // included around the calls.
- request_sigio() {}
- unrequest_sigio() {}
-
- void
- console_change_fontsize(font,fontsize)
- {
- Rect r;
- GrafPtr gp;
- long rows,cols;
-
- GetPort(&gp);
- SetPort(console.wp);
- set_console_font(font,fontsize);
- windowsize2rowscols(&rows,&cols);
- if (rows != console.rows || cols != console.cols) {
- r = console.wp->portRect;
- r.right -= 15;
- EraseRect(&r);
-
- reset_size(rows,cols);
-
- // Tell Emacs
- change_screen_size(console.rows,console.cols,0,0,0);
- }
- SetPort(gp);
- }
-
- static void
- reset_window_preference(void)
- {
- int left,top;
- Rect **rh = (Rect **)NewHandle(sizeof(Rect));
-
- if (!MemError()) {
- **rh = console.wp->portRect;
- if (have_CQD) {
- left = -(**((CGrafPtr)console.wp)->portPixMap).bounds.left;
- top = -(**((CGrafPtr)console.wp)->portPixMap).bounds.top;
- }
- else {
- left = -console.wp->portBits.bounds.left;
- top = -console.wp->portBits.bounds.top;
- }
-
- OffsetRect(*rh,left,top);
- set_preference('DATA',128,rh);
- }
- }
-
- void
- console_grow(EventRecord *e)
- {
- GrafPtr gp;
- long width,height,rows,cols;
- long newsize;
- Rect r,old_portRect,**rh;
-
- r = (**GetGrayRgn()).rgnBBox;
- r.left = r.top = 80;
- newsize = GrowWindow(console.wp,e->where,&r);
- if (newsize == 0) return;
-
- width = LoWord(newsize);
- height = HiWord(newsize);
- if (width == console.wp->portRect.right && height == console.wp->portRect.bottom)
- return;
-
- GetPort(&gp);
- SetPort(console.wp);
- r = console.wp->portRect;
- r.left = r.right - 15;
- InvalRect(&r);
- old_portRect = console.wp->portRect;
- SizeWindow(console.wp,width,height,0);
- r = console.wp->portRect;
- r.left = r.right - 15;
- InvalRect(&r);
- window_depth_cache_valid = 0;
-
- reset_window_preference();
-
- windowsize2rowscols(&rows,&cols);
- if (rows == console.rows && cols == console.cols) return;
-
- r = old_portRect;
- r.right -= 15;
- EraseRect(&r);
- r = console.wp->portRect;
- r.right -= 15;
- EraseRect(&r);
-
- reset_size(rows,cols);
-
- // Tell Emacs. We quote the original source:
- /* This is absolutely, amazingly gross. However, without
- it, emacs will core dump if the window gets too small.
- And uwm is too brain-damaged to handle large minimum size
- windows. */
- if (cols > 11 && rows > 4) {
- /* Delay the change unless Emacs is waiting for input. */
- extern int waiting_for_input;
- // We'll always delay now.
- change_screen_size(console.rows,console.cols,1 || !waiting_for_input,0,0);
- }
-
- SetPort(gp);
- }
-
- void
- console_content(EventRecord *e)
- {
- GrafPtr gp;
- Lisp_Object action,x,y;
-
- if (FrontWindow() != console.wp)
- SelectWindow(console.wp);
- else {
- // This will do until we better emulate X.
- // Need to include an argument with this
-
- GetPort(&gp);
- SetPort(console.wp);
- GlobalToLocal(&e->where);
- SetPort(gp);
- action = Fintern_soft(build_string(
- e->modifiers & shiftKey ? "x-mouse-set-mark" : "x-mouse-set-point"),Qnil);
- if (NULL(action)) { SysBeep(3); return; }
- extract_position(e->where.h,e->where.v,&x,&y);
- XSET(x,Lisp_Int,x);
- XSET(y,Lisp_Int,y);
- action = Fcons(action,Fcons(Fcons(Qquote,Fcons(Fcons(x,Fcons(y,Qnil)),Qnil)),Qnil));
- pass_up_lisp_command(action);
- }
- }
-
- void
- console_drag(EventRecord *e)
- {
- Rect r = (**GetGrayRgn()).rgnBBox;
- DragWindow(console.wp,e->where,&r);
- window_depth_cache_valid = 0;
- reset_window_preference();
- }
-
- WindowPtr
- console_window(void)
- {
- return console.wp;
- }
-
- WCTabHandle
- console_WCTabHandle(void)
- {
- return console.ctab5_color;
- }
-